package com.ruoyi.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.entity.Message;
import com.ruoyi.common.core.mapper.MessageMapper;
import com.ruoyi.common.core.service.BaseServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import static com.ruoyi.service.SysUserServiceImpl.addSystemParam;


/**
 * 用户消息
 * @date 2024-03-22
 */
@Service
public class MessageServiceImpl extends BaseServiceImpl<MessageMapper, Message> {

    /**
     * 查询用户消息
     */
    public void selectPage(Page page, Map<String, Object> param) {
        addSystemParam(param);
        baseMapper.selectPage(page, param);

        //更新为已读
        baseMapper.updateUserRead(SecurityUtils.getUserId());
    }

    /**
     * 新增用户消息
     */
    public void doSave(Message message) {
        message.setCreateTime(DateUtils.getNowDate());
        message.insertOrUpdate();
    }

}
